//
//  BCLocationInterceptor.m
//  BanChinaFramework
//
//  Created by Ann on 2024/3/11.
//

#import "BCLocationInterceptor.h"
#import <CoreLocation/CoreLocation.h>
#import "BCRouterNavigation.h"
#import "BCIPAddressHelper.h"

@interface BCLocationInterceptor()<CLLocationManagerDelegate>

@property (nonatomic, strong) CLLocationManager *locationManager;

@end

@implementation BCLocationInterceptor

- (instancetype)init {
    self = [super init];
    if (self) {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
    }
    return self;
}

- (void)checkAndIntercept {
    [self.locationManager requestWhenInUseAuthorization]; // 请求获取用户位置信息授权
    [self.locationManager startUpdatingLocation]; // 开始更新用户位置信息
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
    CLLocation *location = [locations lastObject];
    // 判断用户所在地区，这里简单地以经度为参考值，实际应用中需要更精确的判断逻辑
    if (location.coordinate.longitude > 73.5 && location.coordinate.longitude < 135.0) {
        // 用户在中国大陆，进行拦截操作
        [self interceptUser];
        if (self.interceptHandlerBlock) {
            self.interceptHandlerBlock(YES);
        }
    }else{
        if (self.interceptHandlerBlock) {
            self.interceptHandlerBlock(NO);
        }
    }
}

- (void)interceptUser {
    // 在这里实现拦截逻辑，可以是弹出提示框或禁止应用继续运行等操作
    NSLog(@"用户在中国大陆，拦截操作执行中...");
}

@end

 
